import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';

Vue.use(VueRouter);

// 解决多次重复点击路由报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

export default new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      children: [
        /* 我的任务 */
        {
          title: '我的任务',
          name: 'user',
          path: 'user/task',
          component: () => import('../views/user/task'),
        },

        /* 我的积分 */
        {
          title: '我的积分',
          name: 'user',
          path: 'user/integral',
          component: () => import('../views/user/integral'),
        },

        /* 内部通知 */
        {
          title: '内部通知',
          name: 'inform',
          path: 'inform/inside',
          component: () => import('../views/inform/inside'),
        },

        /* 行政公告 */
        {
          title: '行政公告',
          name: 'inform',
          path: 'inform/section',
          component: () => import('../views/inform/section'),
        },

        /* 凯拓宪章 */
        {
          title: '凯拓宪章',
          name: 'charter',
          path: 'charter/kai',
          component: () => import('../views/charter/kai'),
        },

        /* 细则规章 */
        {
          title: '细则规章',
          name: 'charter',
          path: 'charter/rules',
          component: () => import('../views/charter/rules'),
        },

        /* 附件表格 */
        {
          title: '附件表格',
          name: 'charter',
          path: 'charter/fu',
          component: () => import('../views/charter/fu'),
        },
      ],
    },
  ],
});